package com.arthur.controller;

import com.arthur.entity.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
public class DeptController_Consumer {
    @Autowired
    private RestTemplate restTemplate;
    //private static final String REST_URL_PREFIX="http://localhost:8001";
    private static final String REST_URL_PREFIX="http://MICROSERVICE-DEPT";
    //添加部门
    @RequestMapping(value = "/consumer/dept/add")
    public boolean addDept(Dept dept){
        return restTemplate.postForObject(REST_URL_PREFIX+"/dept/add",dept,Boolean.class);
    }
    //根据id获取部门
    @RequestMapping(value = "/consumer/dept/find/{id}")
    public Dept findById(@PathVariable("id") Long id) {
        return restTemplate.getForObject(REST_URL_PREFIX+"/dept/find/"+id,Dept.class);
    }
    //获取部门列表
    @RequestMapping(value = "/consumer/dept/list", method = RequestMethod.GET)
    public List<Dept> findAll() {
        return restTemplate.getForObject(REST_URL_PREFIX+"/dept/list",List.class);
    }

    /*** 获取eureka注册列表*/
    @RequestMapping(value = "/consumer/dept/discovery",method = RequestMethod.GET)
    public Object discovery(){
        return restTemplate.getForObject(REST_URL_PREFIX+"/dept/discovery",Object.class);
    }
}
